<template>
	<view class="main">
		<view class="header">
			<view>{{user.name}}</view>
			<view class="info">{{user.username}}</view>
		</view>
		<scroll-view scroll-y class="page" >
<!-- 				<view class="cu-form-group" @tap="goPasswd">
					<view class="title">修改密码</view>
					<text class="lg  cuIcon-right text-gray"></text>
				</view> -->
				<view class="cu-form-group" @tap="goAbout">
					<view class="title">关于</view>
					<text class="lg  cuIcon-right text-gray"></text>
				</view>
				<view class="cu-form-group"  @tap="checkVersion">
					<view class="title">版本号</view>
					<view style="text-align: right;flex-grow: 1;">{{version}}</view>
					<text class="lg  cuIcon-right text-gray"></text>
				</view>
<!-- 				<view class="cu-form-group margin-top"  @tap="showModal">
					<view class="title"></view>
					<view class="title">
						退出登陆 
					</view>
					<view class="title "></view>
				</view> -->
			<view class="cu-tabbar-height"></view>
		</scroll-view>
		<view class="cu-modal" :class="modalName=='confirm'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">系统提示</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					您确认要退出吗？
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-green text-gray" @tap="hideModal">取消</button>
						<button class="cu-btn bg-blue margin-left" @tap="exit">确定</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				modalName: null,
				server_url:'',
				user:{},
				version:''
			}
		},
		created(){
			this.version = plus.runtime.version;
			uni.request({
				url: this.$http+'/sys/sysUser/info',
				header:{
					token:uni.getStorageSync("token")
				},
				success: (res) => {
					this.user = res.data.user;
				}
			})
		},
		methods: {
			showModal: function() {
				this.modalName = "confirm";
				//plus.runtime.quit();  
			},
			exit:function(){
				console.log(1111);
				plus.runtime.quit(); 
			},
			hideModal:function(){
				this.modalName = null;
			},
			goAbout:function(){
				uni.navigateTo({
					url:'../mine/about'
				})
			},
			goPasswd:function(){
				uni.navigateTo({
					url:'../mine/passwd'
				})
			},
			checkVersion:function(){
				uni.request({
					url: this.$http +"/app/v3/checkVersion",
					data: {
						appid:3,
						version:this.version
					},
					method:'POST',
					success: (res) => {
						if (res.statusCode == 200 && res.data.url) {
							let url = res.data.url
							uni.showModal({ //提醒用户更新  
								title: "更新提示",
								content: "系统更新",
								success: (res) => {
									if (res.confirm) {
										console.log(url)
										plus.runtime.openURL(url);
									}
								}
							})
						}else{
							uni.showToast({
								icon: 'none',
								title: '当前已经是最新版本'
							});
						}
					},
					fail:function(){
						uni.showToast({
							icon: 'none',
							title: '服务器请求超时！'
						});
					}
				})
			}
		}
	}
</script>

<style scoped>
	.main {
		display: flex;
		flex-direction: column;
		display: flex;
		align-items: center;
		justify-content: start;
		height: 100vh;
	}

	.header {
		background-image: url(../../static/BasicsBg.png);
		background-size: contain;
		width: 100%;
		height: 437.5rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		color: #fff;
		font-size: 40rpx;
	}
	
	.info {
		color: #d0d0d0;
		font-size: 30rpx;
	}

</style>
